//
//  YSRoomListCell.m
//  Yaoyle
//
//  Created by ZhaoXudong on 14-9-24.
//  Copyright (c) 2014年 ZhaoXudong. All rights reserved.
//

#import "YSRoomListCell.h"
#import "YSGameNumView.h"
#import "UIViewExt.h"
#import "YSUtility.h"

#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]


@implementation YSRoomListCell {
    UILabel *roomNo;
    UILabel *roomStatus;
    UILabel *roomScore;
    
    YSGameNumView *gameNumView;
    
    UILabel *label;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        
        
        UIFont *font = [UIFont systemFontOfSize:13];
        
        roomNo = [[UILabel alloc] init];
        roomNo.font = font;
        roomNo.textAlignment = NSTextAlignmentCenter;
        roomNo.textColor = [UIColor whiteColor];
        [self addSubview:roomNo];
        
        gameNumView = [[YSGameNumView alloc] init];
        
        [self addSubview:gameNumView];
        
        roomStatus = [[UILabel alloc] init];
        roomStatus.font = font;
        roomStatus.textAlignment = NSTextAlignmentCenter;
        roomStatus.textColor = [UIColor whiteColor];
        [self addSubview:roomStatus];
        
        roomScore = [[UILabel alloc] init];
        roomScore.font = font;
        roomScore.textAlignment = NSTextAlignmentCenter;
        roomScore.textColor = [UIColor whiteColor];
        [self addSubview:roomScore];
        
        label = [[UILabel alloc] init];
        label.backgroundColor = UIColorFromRGB(0X000000);
        label.text = @"";
        [self addSubview:label];
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setRoomListModel:(YSRoomModel*)model {
    roomNo.text = model.roomNo;
    [gameNumView setMaxNumber:model.roomMaxNum nowNumber:model.roomNum];
    roomScore.text = model.roomScore;
    roomStatus.text = [YSUtility getGameStatusText:model.roomStatus];
    
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    int nCellHeight = self.frame.size.height;
    
    CGFloat fWidth = 82 ;

    roomNo.frame = CGRectMake(0, 0, fWidth, nCellHeight);
    [gameNumView updateFrame:CGRectMake(roomNo.right, 0, fWidth, nCellHeight)];
    
    roomStatus.frame = CGRectMake(gameNumView.right + 18, 0, fWidth, nCellHeight);
    roomScore.frame = CGRectMake(roomStatus.right+10, 0, fWidth, nCellHeight);
    
    label.frame = CGRectMake(0, 34 - 0.5, self.right, .5);
}
@end
